package at.florian.dulzky.crawler;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class InternetAnalyser {

	static public ArrayList<String> analyzeUrls(String quellcode, String website)
	{
		ArrayList<String> addresses = new ArrayList<String>();
		Matcher m = Pattern.compile("href=\"([^\"]*)\"").matcher(quellcode);
		while(m.find()){
			String address = m.group().replace("href=\"", "").replace("\"", "");			
			Matcher ma = Pattern.compile("^http(s)?://+(.*)*").matcher(address);
			if(!ma.matches()){
				Matcher matchwebsite = Pattern.compile("" + website + "").matcher(address);
				if(!matchwebsite.matches()){
					Matcher absolutePath = Pattern.compile("^/").matcher(address);
					if(!absolutePath.find()){
						address = "http://" + website + "/" + address;
					}else{
						address = "http://" + website + address;
					}
					
				}else{
					address = "http://" + address;
				}
			}
			addresses.add(address);
		}
		return addresses;
	}
}
